package com.dc.commons.config.root;

import org.apache.shiro.spring.LifecycleBeanPostProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.FilterType;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.dc.commons.config.repository.RepositoryConfig;
import com.dc.commons.config.shiro.ShiroConfig;
import com.dc.commons.spring.SpringBeanFactory;
/*******************************************************************************<P>
 * 文件名: RootConfig.java <br>
 * 版本: 1.0 <br>
 * 描述: 基础配置<br>
 * 版权所有: <br>
 * <P>
 * 创建者: 王建栋 <br>
 * 创建日期: 2015年12月17日 上午9:54:34<br>
 * 修改者: <br>
 * 修改日期: <br>
 * 修改说明: <br>
 *****************************************************************************
 */
@Configuration
@EnableTransactionManagement(proxyTargetClass = true)
@EnableAspectJAutoProxy(proxyTargetClass=true)
@ComponentScan(basePackages = "com.dc.modules", useDefaultFilters = false, 
includeFilters = {
		@ComponentScan.Filter(type = FilterType.ANNOTATION, value = {
				Service.class,Repository.class,Component.class})
})
@PropertySource(value={"classpath:META-INF/dc/dc-default.properties","classpath:/dc.properties"},ignoreResourceNotFound=true)
@Import({RepositoryConfig.class,ShiroConfig.class})
@Lazy(false)
public class RootConfig {
	
	private static final Logger logger=LoggerFactory.getLogger(RootConfig.class);
	
	/**
	 * 属性配置器
	 * @return PropertySourcesPlaceholderConfigurer
	 */
	@Bean  
    public static  PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
		logger.debug("propertySourcesPlaceholderConfigurer");
        return new PropertySourcesPlaceholderConfigurer();  
    } 
	
	/**
	 *  Shiro生命周期处理器
	 * @return LifecycleBeanPostProcessor
	 */
	@Bean(name="lifecycleBeanPostProcessor")
	public LifecycleBeanPostProcessor lifecycleBeanPostProcessor(){
		return new LifecycleBeanPostProcessor();
	}
	
	/**
	 * BeanFactory 配置
	 * @return SpringBeanFactory
	 */
	@Bean
	public SpringBeanFactory springBeanFactory(){
		return new SpringBeanFactory();
	}
	
}
